package com.jxstyle.core.security;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.userdetails.User;
import org.springframework.stereotype.Component;

import com.jxstyle.config.SecurityConfig;

/**
 * 退出成功处理
 * 
 * @author weijx
 *
 */
@Component
public class LogoutSuccessHandler
		implements org.springframework.security.web.authentication.logout.LogoutSuccessHandler {

	private static final Logger logger = LoggerFactory.getLogger(SecurityConfig.class);

	@Override
	public void onLogoutSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication)
			throws IOException, ServletException {
		try {
			User user = (User) authentication.getPrincipal();
			logger.info("USER : " + user.getUsername() + " LOGOUT SUCCESS !  ");
		} catch (Exception e) {
			logger.info("LOGOUT EXCEPTION , e : " + e.getMessage());
		}
		response.sendRedirect("/login");
	}

}
